<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/21 0021
 * Time: 14:34
 */

namespace app\home\controller\index;
use app\home\controller\Base;
use app\home\model\report\Detection;
use app\home\model\report\DetectionCate;
use app\home\service\CodeService;
use think\Db;

class Index extends Base
{
    public function index(){
        $status     =input("status");
        if(Request()->isPost()){
            $banner=Db::table('banner')
                ->field('banner_pic,banner_url,banner_name')
                ->where(["pos"=>1,"banner_state"=>1,"status"=>($status == 2)?2:1])
                ->order("banner_id desc")
                ->find();
            $status=!empty($banner)?1:0;
            if(empty($banner)){
                $banner['banner_pic']  ='';
                $banner['banner_url']  ='';
                $banner['banner_name'] ='';
            }
            $result[]  =[
                "headerTitle" => "banner弹窗图",
                "type"        => 4,
                "isHideHeader"=> 4,
                "data"        =>[
                    "banner" =>$banner,
                    "status" =>$status,
                ]
            ];
            //测评推荐
            $Detection  =   new Detection();
            $dc         =   $Detection->where([
                "status"=>"Y",
                "recommend"=>1
            ])
                ->field(['d_id','title','describe','img_plot','is_pay','buy_count','price_original'])
                ->limit(0,2)
                ->order("sort asc,create_time desc")
                ->select();
            $result[]  =[
                "headerTitle" => "每日推荐",
                "type"        => 5,
                "isHideHeader"=> 5,
                "data"        =>[
                    'detection' =>$dc,
                    "status"    =>!empty($dc)?1:0
                ]
            ];
            //测评分类
            $cate       = DetectionCate::getCate(['c_status'=>"Y"]);
            $result[]   =[
                "headerTitle" => "精选测评",
                "type"        => 6,
                "isHideHeader"=> 6,
                "data"        =>[
                    'detection' =>$cate,
                    "status"    =>!empty($cate)?1:0
                ]
            ];
            return CodeService::response(200,CodeService::SUCCESS,$result);
        }else{
            return CodeService::REQUEST_METHOD_ERROR;
        }
    }
}